//
//  SwiftUIShape.swift
//  SwiftUICode
//
//  Created by yangkl on 2024/2/19.
//

import SwiftUI

struct SwiftUIShape: View {
    var body: some View {
        ZStack {
            Path(){ path in
                path.move(to: CGPoint(x: 20, y: 20))
                path.addLine(to: CGPoint(x: 60, y: 20))
                path.addQuadCurve(to: CGPoint(x: 260, y: 20), control: CGPoint(x: 160, y: -30))
                path.addLine(to: CGPoint(x: 300, y: 20))
                path.addLine(to: CGPoint(x: 300, y: 200))
                path.addLine(to: CGPoint(x: 20, y: 200))
                path.closeSubpath()
            }
            .fill(.green)
            
            Path(){ path in
                path.move(to: CGPoint(x: 20, y: 20))
                path.addLine(to: CGPoint(x: 60, y: 20))
                path.addQuadCurve(to: CGPoint(x: 260, y: 20), control: CGPoint(x: 160, y: -30))
                path.addLine(to: CGPoint(x: 300, y: 20))
                path.addLine(to: CGPoint(x: 300, y: 200))
                path.addLine(to: CGPoint(x: 20, y: 200))
                path.closeSubpath()
            }
            .stroke(Color.purple, lineWidth: 10)
        }
    }
}

struct ArcView: View{
    var body: some View{
        ZStack {
            Path { path in
                path.move(to: CGPoint(x: 200, y: 200))
                path.addArc(center: CGPoint(x: 200, y: 200), radius: 150, startAngle: .degrees(0), endAngle: .degrees(170), clockwise: true)
            }
            .fill(.red)
            Path { path in
                path.move(to: CGPoint(x: 200, y: 200))
                path.addArc(center: CGPoint(x: 200, y: 200), radius: 150, startAngle: .degrees(170), endAngle: .degrees(90), clockwise: true)
            }
            .fill(.green)
            Path { path in
                path.move(to: CGPoint(x: 200, y: 200))
                path.addArc(center: CGPoint(x: 200, y: 200), radius: 150, startAngle: .degrees(90), endAngle: .degrees(0), clockwise: true)
            }
            .fill(.blue)
            .offset(x: /*@START_MENU_TOKEN@*/10.0/*@END_MENU_TOKEN@*/, y: 10)
            .overlay{
                Text("25%").font(.system(size: 20, design: .rounded))
                    .foregroundColor(.white)
                    .offset(x:70, y:-100)
            }
        }
    }
}

struct DomeButton: View {
    var body: some View {
        Button{
            
        }label: {
            Text("Hello world")
                .font(.title)
                .foregroundColor(.white)
                .frame(width: 250, height: 50)
                .background(Dome().fill(.green))
        }
    }
}

#Preview {
    SwiftUIShape()
}

#Preview {
    ArcView()
}

#Preview {
    DomeButton()
}
